package com.crm.service.user;

import com.crm.pojo.User;
import com.crm.repository.UserRepository;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserRepository userRepository;

    @Override
    public User login(String usrName) {
        return userRepository.findUserByUsrName(usrName);
    }

    @Override
    public List<User> findUsersByRoleName() throws Exception {
        return userRepository.findUsersByRole();
    }

    @Override
    public User findUserByRoleNameAndUsrId(Long usrId) throws Exception {
        return userRepository.findUserByRoleNameAndUsrId(usrId);
    }

    @Override
    public String encryptPassword(Object plaintextPassword) throws IllegalArgumentException {
        String salt = "zp";
        Md5Hash md5Hash = new Md5Hash(plaintextPassword, salt, 2);
        System.out.println(md5Hash.toString());

        return md5Hash.toString();
    }
}